//
// Created by Administrator on 2022/10/10.
//

#ifndef HTTPSERVER_HTTP_REQUEST_H
#define HTTPSERVER_HTTP_REQUEST_H

// http请求类型数量
#define REQ_TYPE_NUM 10

#define HEADER_END_TARGET_LEN 4

#define HEADER_LINE_END_TARGET_LEN 2
#define HEADER_LINE_END_TARGET "\R\N"

#define HTTP_UNKNOWN                    0x00000001
#define HTTP_POST                       0x00000002
#define HTTP_GET                        0x00000004
#define HTTP_HEAD                       0x00000008
#define HTTP_PUT                        0x00000010
#define HTTP_PATCH                      0x00000020
#define HTTP_OPTIONS                    0x00000040
#define HTTP_DELETE                     0x00000080
#define HTTP_CONNECT                    0x00000100
#define HTTP_TRACE                      0x00000200
static const char* req_target[REQ_TYPE_NUM] = {"UNKNOWN", "POST", "GET", "HEAD", "PUT", "PATCH", "OPTIONS", "DELETE", "CONNECT", "TRACE"};

typedef struct req_header_s req_header_t;

struct req_header_s{
    int fd;
    dts head;
    dts body;
    int head_len;
    char buf[200];
    int buf_len;
    req_attr_t *attr;
    struct http_fd_s *fds;
    struct http_socket_event_s *hset;
    struct body_stream_t req_stream;
};
/************     http_req_header.c       ***************/
struct requestContext {
    int fd;
    dts home;
    dts reqType;
    dts reqPath;
    dts version;
    dts head;
    dts body;
    struct http_fd_s *fds;
    struct http_socket_event_s *hset;
};
void init_req_attr(struct request_head_attr_s* attr);

void _req_analysis_head(req_header_t *header);
void _req_analysis_body(req_header_t *header);
void _clear_req_head(req_attr_t *attr);
void _before_request_callback(req_header_t *header);
void _running_request_callback(req_header_t *header);
void _after_request_callback(req_header_t *header);

void requst_control(req_header_t *header);

void __socket_w_callback(struct http_socket_event_s *hset, int fd);
void ___socket_r_callback(struct http_socket_event_s *hset, int fd);
#endif //HTTPSERVER_HTTP_REQUEST_H
